/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Materials;

import Raytracing.Shaders.Shader;
import Raytracing.BRDF.LambertBRDF;
import Raytracing.Shaders.SolidTexture;
import SGGUI.GUIComponent;
import SGGUI.GUIEvent;
import SGGUI.GUIListener;
import SGGUI.SGSlider;
import TweetRay.Exportable;
import Materials.MaterialFactory.Materials;
import TweetRay.UTFWriter;
import processing.core.PVector;

/**
 *
 * @author Matt
 */
public class P3C6Shader extends Shader implements GUIListener {

    protected PVector color;

    public void setColor(PVector color) {
        this.color = color;
        setFillColor(color);
    }

    public void setParam(float param) {
        this.param = param;
    }
    private float param;
    private String paramName = "param";
    protected GUIComponent[] controls;

    public P3C6Shader(String name) {
        super(name);


    }

    public P3C6Shader(String name, String paramName, PVector color) {
        super(name);
        this.color = color;
        this.paramName = paramName;
      
    }

    public void init() {
        controls = new GUIComponent[4];
        controls[0] = new SGSlider("Param", param, 1 / 7f, 0, 1.f);
        controls[0].addGUIListener(this);
        controls[1] = new SGSlider("Red", color.x, 1 / 4f, 0, 1.f);
        controls[1].addGUIListener(this);
        controls[2] = new SGSlider("Green", color.y, 1 / 4f, 0, 1.f);
        controls[2].addGUIListener(this);
        controls[3] = new SGSlider("Blue", color.z, 1 / 4f, 0, 1.f);
        controls[3].addGUIListener(this);
        setControls(controls);

    }

    public void GUIEventPerformed(GUIEvent e) {

        param = ((SGSlider) controls[0]).val;

        if (e.title.equals("Red")) {
            fillColor.x = e.val;
            color.x = e.val;
        }
        if (e.title.equals("Green")) {
            fillColor.y = e.val;
            color.y = e.val;
        }
        if (e.title.equals("Blue")) {
            fillColor.z = e.val;
            color.z = e.val;
        }
        fill = 0xff000000 | ((int) (fillColor.x * 255) << 16)
                | ((int) (fillColor.y * 255) << 8)
                | (int) (fillColor.z * 255);

    }

    public void writeColorBits(UTFWriter output) {


        output.writeBits((int) (((SGSlider) controls[0]).val * 7), 3);

        output.writeBits((int) (fillColor.x * 3), 2);
        output.writeBits((int) (fillColor.y * 3), 2);
        output.writeBits((int) (fillColor.z * 3), 2);

    }
}
